get_antigen_screen_result返回统计数据
返回受保护的手机号和名字

FFIB 2 年之前
父节点
当前提交
6d11212a03
共有 2 个文件被更改,包括 46 次插入3 次删除
  1. 20 1
      api/antigen_views.py
  2. 26 2
      equipment/models.py

+ 20 - 1
api/antigen_views.py

@@ -2,6 +2,9 @@
2 2
 
3 3
 from __future__ import division
4 4
 
5
+import datetime
6
+
7
+from django.conf import settings
5 8
 from django.db.models import Q
6 9
 from django_logit import logit
7 10
 from django_response import response
@@ -50,10 +53,26 @@ def get_antigen_screen_data(point_id):
50 53
     except IsolationPointInfo.DoesNotExist:
51 54
         return response(IsolationPointStatusCode.ISOLATIONPOINT_NOT_FOUND)
52 55
 
56
+    now_dt = datetime.datetime.now()
57
+    zero_dt = now_dt - datetime.timedelta(hours=now_dt.hour, minutes=now_dt.minute, seconds=now_dt.second, microseconds=now_dt.microsecond)
58
+
53 59
     ipuis = IsolationPointUserInfo.objects.filter(point_id=point_id, status=True).order_by('-detect_at')
60
+    total_active_eqpt_num = ipuis.count()
61
+    antigen_negative_num = ipuis.filter(antigen_result=IsolationPointUserInfo.NEGATIVE, detect_at__gte=zero_dt).count()
62
+    antigen_positive_num = ipuis.filter(antigen_result=IsolationPointUserInfo.POSITIVE, detect_at__gte=zero_dt).count()
63
+    temperature_normal_num = ipuis.filter(temperature__lte=settings.FEVER_TEMPERATURE, last_submit_at__gte=zero_dt).count()
64
+    temperature_fever_num = ipuis.filter(temperature__gt=settings.FEVER_TEMPERATURE, last_submit_at__gte=zero_dt).count()
54 65
     ipuis = [ipui.antigen_screen_data for ipui in ipuis]
55 66
 
56
-    return ipuis
67
+    return {
68
+        'eqpts': ipuis,
69
+        'total_active_eqpt_num': total_active_eqpt_num,
70
+        'antigen_negative_num': antigen_negative_num,
71
+        'antigen_positive_num': antigen_positive_num,
72
+        'temperature_normal_num': temperature_normal_num,
73
+        'temperature_fever_num': temperature_fever_num,
74
+        'update_time': tc.local_string(),
75
+    }
57 76
 
58 77
 
59 78
 @logit(body=True)

+ 26 - 2
equipment/models.py

@@ -251,6 +251,29 @@ class IsolationPointUserInfo(BaseModelMixin):
251 251
             return u'今日未检测'
252 252
 
253 253
     @property
254
+    def get_temperature_result(self):
255
+        today = datetime.date.today()
256
+        if not self.last_submit_at:
257
+            return u'今日未测温'
258
+
259
+        if today.day == self.last_submit_at.day and today.month == self.last_submit_at.month and today.year == self.last_submit_at.year:
260
+            return self.temperature
261
+        else:
262
+            return u'今日未测温'
263
+
264
+    @property
265
+    def get_protected_name(self):
266
+        name = list(self.name)
267
+        name[1] = '*'
268
+        return ''.join(name)
269
+
270
+    @property
271
+    def get_protected_phone(self):
272
+        phone = list(self.phone)
273
+        phone[3:7] = '****'
274
+        return ''.join(phone)
275
+
276
+    @property
254 277
     def data(self):
255 278
         return {
256 279
             'pk': self.pk,
@@ -308,8 +331,9 @@ class IsolationPointUserInfo(BaseModelMixin):
308 331
             'observed_days': self.antigen_observed_days,
309 332
             'last_report_time': tc.local_string(utc_dt=self.detect_at, format='%m-%d %H:%M') if self.detect_at else '',
310 333
             'remark': self.remark or '',
311
-            'name': self.name,
312
-            'phone': self.phone,            
334
+            'name': self.get_protected_name,
335
+            'phone': self.get_protected_phone,
336
+            'temperature': self.get_temperature_result,            
313 337
             'antigen_result': self.get_antigen_result,
314 338
         }
315 339